﻿using SheBao.Model;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace SheBao.EFDAL
{
    public class DbContextFactory
    {
        /// <summary>
        /// 保证上下文唯一
        /// </summary>
        /// <returns></returns>
        public static DbContext GetCurrentDbContext()
        {
            DbContext db = HttpContext.Current.Items["DbContext"] as DbContext;
            if (db == null)
            {
                db = new shebaofqEntities();
                HttpContext.Current.Items.Add("DbContext", db);
            }
            return db;
        }
    }
}
